package com.itheima.service.Impl;

import com.itheima.VO.CheckItemVO;
import com.itheima.common.entity.PageResult;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;


    /**
     * 新增检查项
     * @param checkItem
     */
    public void insert(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }


    /**
     * 查询全部数据
     * @param checkItem
     * @return
     */
    public List<CheckItemVO> list(CheckItem checkItem) {
        return checkItemMapper.findAll(checkItem);
    }

    /**
     * 根据id删除检查项
     * @param id
     */
    public void deleteById(Integer id) {
        checkItemMapper.deleteById(id);
    }

    /**
     * 编辑检查项
     * @param checkItem
     */
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public PageResult page(Integer currentPage, Integer pageSize) {
        //1.获取总记录数
        Long count = checkItemMapper.count();
        //2.获取分页查询结果列表
        Integer start=(currentPage-1)*pageSize;
        List<CheckItem> list=checkItemMapper.page(start,pageSize);
        //3.封装PageResult对象
        PageResult pageResult = new PageResult(count, list);
        return pageResult;

    }

    /**
     * /**
     *根据id查询检查项
     * @param id
     * @return
     */
    @Override
    public CheckItem findById(Integer id) {

        return checkItemMapper.findById(id);
    }


    /**
     * 根据groupid查询itemid表
     * @return
     */
    @Override
    public List<CheckItem> getItemById(Integer id) {
        return checkItemMapper.findCheckItemsByCheckGroupId(id);
    }
}
